home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / src / http_rqueue.c < prev    next >
C/C++ Source or Header  |  1995-05-18  |  2KB  |  86 lines

  1. /***************************************************************************
  2.  * This file contains the request queue for file descriptors from accepted *
  3.  * connections.                                                            *
  4.  * Copyright 1995 Brandon Long (blong@uiuc.edu)                            *
  5.  * For ACM@UIUC HTTPD 1.3.3                                                *
  6.  ***************************************************************************/
  7.  
  8. /*http_rqueue.c,v 1.1 1995/02/23 09:18:49 blong Exp
  9. **http_rqueue.c,v
  10.  * Revision 1.1  1995/02/23  09:18:49  blong
  11.  * Update to 1.4beta from ACM 1.3.3
  12.  * Adds round robin stay alive children processes and Error Document direction
  13.  *
  14.  */
  15.  
  16.  
  17. #include "httpd.h"
  18. #include "queue.h"
  19.  
  20. queue* createQueue() {
  21.     queue* newq;
  22.  
  23.     newq = (queue *)malloc(sizeof(queue));
  24.     newq->Front = NULL;
  25.     newq->Back = NULL;
  26.     newq->num = 0;
  27.  
  28.     return newq;
  29. }
  30.  
  31.  
  32. /* Some may disagree, but I've allows thought of queues as you put it in
  33. on the front, and take it out the back, so this is how I made it. */
  34.  
  35. int enQueue(queue* q, int newfd) {
  36.     queueRec* Rec;
  37.  
  38.     Rec = (queueRec *)malloc(sizeof(queue));
  39.  
  40.     Rec->Data = newfd;
  41.  
  42.     if ((q->Front == NULL) && (q->Back == NULL)) {
  43.     Rec->Next = NULL;
  44.     Rec->Prev = NULL;
  45.     q->Front = Rec;
  46.     q->Back = Rec;
  47.     } else {
  48.     Rec->Next = q->Front;
  49.     q->Front->Prev = Rec;
  50.     Rec->Prev = NULL;
  51.     q->Front = Rec;
  52.     }
  53.  
  54.     q->num++;
  55.     return q->num;
  56. }
  57.     
  58. int deQueue(queue* q) {
  59.     queueRec* tmp;
  60.     int oldfd;
  61.  
  62.     if ((q->Front != NULL) && (q->Back != NULL)) {
  63.     if (q->Front == q->Back) {
  64.         tmp = q->Back;
  65.         oldfd = tmp->Data;
  66.         free(tmp);
  67.         q->Back = NULL;
  68.         q->Front = NULL;
  69.         q->num = 0;
  70.         return oldfd;
  71.     } else {    
  72.         tmp = q->Back;
  73.         oldfd = q->Back->Data;
  74.         q->Back = q->Back->Prev;
  75.         q->Back->Next = NULL;
  76.         q->num--;
  77.         free(tmp);
  78.         return oldfd;
  79.     }
  80.     } else return -1; /* return -1 on error (queue empty) */
  81. }
  82.     
  83. int numQueue(queue* q) {
  84.     return q->num;
  85. }
  86.